package com.xdemo.community.server;


import javax.script.Bindings;
import javax.script.SimpleBindings;

import com.meetup.memcached.Logger;
import com.meetup.memcached.MemcachedClient;
import com.xdemo.community.socketserver.CommunitySocketServer;
import com.xdemo.core.ScriptManager;

public class CommunityServer {
	
	private CommunityServerConfig serverConfig = new CommunityServerConfig();

	private ScriptManager scriptManager = new ScriptManager("resource");
	
	public static void main(String[] args) {
		Logger.getLogger( MemcachedClient.class.getName() ).setLevel( Logger.LEVEL_WARN );

		CommunityServer _server = new CommunityServer();
		_server.config();
		_server.start();
	}
	
	public void config() {
		Bindings _bindings = new SimpleBindings();
		_bindings.put("server", serverConfig);
		scriptManager.runScript("server.config.js", _bindings);
	}
	
	public void start() {
		CommunitySocketServer _socketServer = new CommunitySocketServer(serverConfig);
		_socketServer.start();
	}
}
